#Twisted Shootout
#Copyright (C) 2007 Han Dao
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

#You can contact the author at wikipediankiba@gmail.com

import pygame
import data
import texttype
pygame.font.init
class Text:
	def __init__(self):
		self.data = data.read
		self.messages = []
		self.pos = []
		self.results = []
		self.font = pygame.font.Font(self.data.font(),12)
		self.texttype = texttype.TextType(self)
	def changesize(self,size):
		self.font = pygame.font.Font(self.data.font(), size)
	def add(self,message,pos):
		self.messages.append(message)
		self.pos.append(pos)
	def render(self,display):
		n = 0
		for m in self.messages:
		    result = self.font.render(m, False, (0,0,255))
		    self.results.append(result)
		    display.blit(result,[self.pos[n][0],self.pos[n][1]])
		    n = n + 1
	def switch(self):
		if self.texttype.switch == False:
		    self.texttype.switch = True
		elif self.texttype.switch == True:
		    self.texttype.switch = False
	def access(self,k):
		self.texttype.typing(k)
		self.texttype.delete(k)
		self.texttype.enter(k)
	def poststring(self,p):
		self.pos.append(p)
		self.messages.append(" ")
	def execute(self,display):
	      string = self.texttype.datareturn()
	      if string != False:
		  self.messages[-1] = string
	      else:
		  self.messages[-1] = ' '
	      self.render(display)